/*
**  common.h
**  Copyright 2011, Zane Sims
**
**  This file is part of brick-breaker-game.
**
**  brick-breaker-game is free software: you can redistribute it
**  and/or modify it under the terms of the GNU General Public
**  License as published by the Free Software Foundation, either
**  version 3 of the License, or (at your option) any later version.
**
**  brick-breaker-game is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with brick-breaker-game.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COMMON_H
#define COMMON_H

#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>

#define GAME				1
#define EDITOR				2

#define SMALL_PADDLE		0
#define MEDIUM_PADDLE		1
#define LARGE_PADDLE		2
#define XLARGE_PADDLE		3

#define BRICK_GRID_W		20
#define BRICK_GRID_H		25
#define BRICK_W				38
#define BRICK_H				17

#define BRICK_TYPE_NONE			0 /* there is no brick */
#define BRICK_TYPE_NORMAL		1 /* a normal breakable brick */
#define BRICK_TYPE_UNBREAKABLE	2 /* cannot be broken...unless with super ball...does NEED to be broken */
#define BRICK_TYPE_INVISIBLE	3 /* invisible brick that can be broken */
#define BRICK_TYPE_EXPLODING	4 /* exploding brick */

typedef struct _Brick
{
	unsigned char img_index;
	unsigned char type;
	float x;
	float y;
	int explode_tick;
}Brick;

extern int APP_MODE;
extern int BRICK_GRID_X1;
extern int BRICK_GRID_Y1;
extern int BRICK_GRID_X2;
extern int BRICK_GRID_Y2;

extern int bricks_remaining;

extern ALLEGRO_BITMAP *explode_imgs[5];
extern ALLEGRO_BITMAP *item_imgs[5];
extern ALLEGRO_BITMAP *brick_imgs[40];
extern ALLEGRO_BITMAP *start_screen_img;
extern ALLEGRO_BITMAP *ball_img;
extern ALLEGRO_BITMAP *paddle_img[4];
extern ALLEGRO_BITMAP *left_wall_img;
extern ALLEGRO_BITMAP *right_wall_img;
extern ALLEGRO_BITMAP *top_wall_img;
extern Brick bricks[BRICK_GRID_W][BRICK_GRID_H];

void draw_bricks(int show_invis);
int load_level(const char* filename);
void load_images();
void free_images();
int point_in_rect(int px, int py, int rx1, int ry1, int rx2, int ry2);
void error_exit(const char* error_str);

#endif


